package com.netty.demo.text.securechat;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;

public class SecureChatServerInitializer extends ChannelInitializer<SocketChannel> {

//    private final SslContext sslCtx;

//    public SecureChatServerInitializer(SslContext sslCtx) {
//        this.sslCtx = sslCtx;
//    }

    @Override
    protected void initChannel(SocketChannel channel) throws Exception {
        ChannelPipeline pipeline = channel.pipeline();
//        pipeline.addLast(sslCtx.newHandler(channel.alloc()));
        // On top of the SSL handler, add the text line codec.
        pipeline.addLast(new DelimiterBasedFrameDecoder(8192, Delimiters.lineDelimiter()));
        pipeline.addLast(new StringEncoder()).addLast(new StringDecoder());
        // and then business logic.
        pipeline.addLast(new SecureChatServerHandler());
    }
}
